using ScFramework.Utilities;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.SceneManagement;
using Random = UnityEngine.Random;
using System.Reflection;
using System.IO;
using System.Globalization;

namespace ScFramework.Core
{
    public class DataUtil : SystemModule
    {
        static DataUtil _instance = null;
        public string PersistentDataPath => Application.persistentDataPath+"/";
        #region 读表类函数,基层轮子

        private readonly TableAgent _tableAgent = new TableAgent();
        public static DataUtil Instance => _instance;
        public static TableAgent Table
        {
            get { return _instance._tableAgent; }
        }

        public static string ReadFromFile(string path)
        {
            System.IO.StreamReader sr = new System.IO.StreamReader(path);
            string content = string.Empty;
            content = sr.ReadToEnd();
            sr.Close();
            return content;
        }
        public static void SaveToFile(string path,string s)
        {


            System.IO.File.Create(path).Dispose();
            System.IO.StreamWriter sw = new System.IO.StreamWriter(path);
            sw.Write(s);
            sw.Close();
        }
        public void SetTableAgent()
        {
            var list = _main.Get<ResourceManager>().LoadAll<TextAsset>("Text/Table/");
            for (int i = 0; i < list.Length; i++)
            {
                _tableAgent.Add(list[i].text);
            }
        }
        #endregion

        public override void Initialize(Main m)
        {
            _instance = this;
            base.Initialize(m);
            SetTableAgent();
        }

        public override void SysUpdate(float deltaTime)
        {
            //   throw new NotImplementedException();
        }

        public override void SysFixedUpdate(float deltaTime)
        {
            //     throw new NotImplementedException();
        }

        public override void Dispose()
        {
            //    throw new NotImplementedException();
        }


    }
}